<template>
    <div class="mainBox">
        <PageHeaderNav :need-underline="false" :need-back="true" content="功能设置"></PageHeaderNav>
        <div class="aui-list-item">
            <div class="item btnFocus speech"
                 v-for="button in listButton"
            >
                <img :src="button.img" alt="">
                <p>{{ button.content }}</p>

                <el-switch
                    v-model="button.status"
                    active-color="#13ce66"
                    @change="changeSettingForAudio"
                >
                </el-switch>
            </div>
        </div>
    </div>
</template>

<script>
import PageHeaderNav from "@/components/Publlic/PageHeaderNav.vue";

export default {
    components: {
        PageHeaderNav,
    },

    data() {
        return {
            listButton: [
                {
                    img: require("@/assets/images/searchView/audio.png"),
                    content: "语音播报",
                    status: this.$store.state.UserModule.userInfo.needAudio,
                },
                {
                    img: require("@/assets/images/searchView/clock.png"),
                    content: "用药超时提醒",
                    status: false,
                }
            ]
        }
    },

    methods: {
        changeSettingForAudio() {
            const needAudio = this.listButton[0].status
            console.log(needAudio)
            this.request.post("/user/changeSettingForAudio/", {
                needAudio: needAudio
            }).then((response) => {
                const status = response["code"] === 200

                if (status) {
                    this.$store.state.UserModule.userInfo.needAudio = needAudio
                } else {
                    this.listButton[0].status = !needAudio
                }
            }).catch(error => {
                this.listButton[0].status = !needAudio
            })
        }
    }
}
</script>

<style lang="less">
.mainBox {
    width: 100%;
    height: 100%;
    background-color: var(--grayColor);
}

.page-header-box {
    background-color: white;
}

.aui-list-item {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    box-sizing: border-box;
    margin: 15px;

    .item {
        width: 100%;
        height: 72px;
        margin: 5px 0;
        padding-left: 15px;
        padding-right: 15px;
        box-sizing: border-box;
        background-color: white;
        border-radius: 15px;
        display: flex;
        align-items: center;
        box-shadow: var(--grayColor) 0 0 5px;
        border: var(--grayColor) solid 1px;
        position: relative;

        .el-switch {
            position: absolute;
            right: 15px;
        }
    }

    .item img {
        width: 40px;
        margin-right: 20px;
    }
}
</style>